package com.zhuiYun.project.api.trend.mapper;

import com.zhuiYun.project.api.trend.entity.TrendContent;
import com.zhuiYun.project.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @Author gpd
* @Description 动态内容mapper
* @Date 2023-04-17 下午 04:41
* @Return

*/

@Mapper
public interface TrendContentMapper extends BaseMapper<TrendContent> {

    @Select("SELECT\n" +
            "            c.*,\n" +
            "            ( CASE WHEN ( t.id IS NULL OR t.id = '' ) THEN '0' ELSE 1 END ) AS flag \n" +
            "            FROM\n" +
            "            trend_content c\n" +
            "            LEFT JOIN ( SELECT * FROM trend_thumb tt WHERE tt.user_id = #{userId} ) t ON c.id = t.trend_id \n" +
            "            WHERE\n" +
            "            del_flag = 0 \n" +
            "            and c.publish_status = 0 \n" +
            "            ORDER BY\n" +
            "            likes DESC")
    @Results({
            @Result(property = "thumbFlag" , column = "flag")
    })
    // 查询用户发布的所有动态
    List<TrendContent> getUserTrends(Integer userId);

    @Select("SELECT\n" +
            "\tc.*,\n" +
            "\t( CASE WHEN ( t.id IS NULL OR t.id = '' ) THEN '0' ELSE 1 END ) AS flag \n" +
            "FROM\n" +
            "\ttrend_content c\n" +
            "\tLEFT JOIN ( SELECT * FROM trend_thumb tt WHERE tt.user_id = #{userId}) t ON c.id = t.trend_id \n" +
            "WHERE\n" +
            "\tdel_flag = 0 \n" +
            "\tAND c.id =#{id}")
    @Results({
            @Result(property = "thumbFlag" , column = "flag")
    })
    // 查询用户选择的动态
    TrendContent getUserSelectTrend(Integer id,Integer userId);


}
